package com.hugy.test.rabbitmq01;

import com.hugy.test.basic.RabitMQConnection;
import com.hugy.test.basic.Constants;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 蚂蚁课堂创始人-余胜军QQ644064779
 * @title: Producer
 * @description: 每特教育独创第五期互联网架构课程
 * @date 2019/12/322:11
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        System.out.println("生产者启动成功..");
        // 1.创建我们的连接
        Connection connection = RabitMQConnection.getConnection();
        // 2.创建我们通道
        Channel channel = connection.createChannel();
        for (int i = 0; i < 10; i++) {
            // 开启生产确认消息投递机制
            channel.confirmSelect();
            String msg = "每特教育第六期突破3万月薪" + i;
            channel.basicPublish("", Constants.BASIC_QUEUE_NAME, null, msg.getBytes());
            if (channel.waitForConfirms()) {
                System.out.println("生产者发送消息成功:" + msg);
            }
        }
        channel.close();
        connection.close();
    }
}
